using TerritoryGame.Domain.Common;
using TerritoryGame.Domain.ValueObjects;

namespace TerritoryGame.Domain.Entities;

/// <summary>
/// 玩家实体
/// </summary>
public class Player : Entity<PlayerId>
{
    public PlayerNickname Nickname { get; private set; }
    public PlayerColor Color { get; private set; }
    public int Area { get; private set; }
    public bool IsOwner { get; private set; }
    public DateTime JoinedAt { get; private set; }
    
    // EF Core 构造函数
    private Player() { }
    
    public Player(PlayerId id, PlayerNickname nickname, bool isOwner = false)
    {
        Id = id;
        Nickname = nickname;
        Color = PlayerColor.None;
        Area = 0;
        IsOwner = isOwner;
        JoinedAt = DateTime.UtcNow;
    }
    
    /// <summary>
    /// 分配颜色
    /// </summary>
    public void AssignColor(PlayerColor color)
    {
        Color = color;
    }
    
    /// <summary>
    /// 更新面积
    /// </summary>
    public void UpdateArea(int area)
    {
        Area = area;
    }
    
    /// <summary>
    /// 设置为房主
    /// </summary>
    public void SetAsOwner()
    {
        IsOwner = true;
    }
    
    /// <summary>
    /// 重置玩家状态
    /// </summary>
    public void Reset()
    {
        Color = PlayerColor.None;
        Area = 0;
    }
}
